/** Taken from "The Definitive ANTLR 4 Reference" by Terence Parr */

// Derived from https://json.org

// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging

parser grammar BpmParser;

options {
   tokenVocab=BpmLexer;
}

model
   : OPEN MXGRAPHMODEL CLOSE root OPEN SLASH MXGRAPHMODEL CLOSE EOF
   ;

root
   : OPEN ROOT CLOSE cell* OPEN SLASH ROOT CLOSE
   ;

cell
   : OPEN MXCELL attribute* CLOSE content* OPEN SLASH MXCELL CLOSE
   | OPEN MXCELL attribute* SLASH_CLOSE
   ;

attrName
   : ID
   | PARENT
   | STYLE
   | VERTEX
   | AS
   | EDGE
   | SOURCE
   | TARGET
   | VALUE
   | NAME
   | DESCRIPTION
   | CALLABLE
   | METHOD
   | HEIGHT
   | WIDTH
   | TYPE
   | X
   | Y
   | RELATIVE
   | INDEX
   | REENTERABLE
   ;

behaviorName
   :AUTO_TASK
   |STATEFUL_TASK
   |FLOW
   |DECISION
   |SWITCH_TASK
   |FORK
   |JOIN
   |START
   |END
   ;

attribute
   : name = attrName EQUALS value = STRING
   ;

content
   : geometry
   | behavior
   ;

geometry
   : OPEN MXGEOMETRY attribute* SLASH_CLOSE
   | OPEN MXGEOMETRY attribute* CLOSE point (point)* (pointArray)* OPEN SLASH MXGEOMETRY CLOSE
   ;

point
   : OPEN MXPOINT attribute* SLASH_CLOSE
   ;

pointArray
   : OPEN ARRAY attribute* CLOSE point (point)* OPEN SLASH ARRAY CLOSE
   ;

param
   : OPEN PARAM attribute* SLASH_CLOSE
   ;

return
   : OPEN RETURN attribute* SLASH_CLOSE
   ;

callDef
   : OPEN CALL attribute* CLOSE paramArray? returnArray? OPEN SLASH CALL CLOSE
   | OPEN CALL attribute* SLASH_CLOSE
   ;

exceptionHandlerDef
   : OPEN EXCEPTION_HANDLER attribute* CLOSE paramArray? returnArray? OPEN SLASH EXCEPTION_HANDLER CLOSE
   | OPEN EXCEPTION_HANDLER attribute* SLASH_CLOSE
   ;

paramArray
   : OPEN ARRAY attribute* CLOSE param (param)* OPEN SLASH ARRAY CLOSE
   ;

returnArray
   : OPEN ARRAY attribute* CLOSE return (return)* OPEN SLASH ARRAY CLOSE
   ;

behavior
   : OPEN name = behaviorName attribute* SLASH_CLOSE
   | OPEN name = behaviorName attribute* CLOSE callDef callDef? exceptionHandlerDef? OPEN SLASH behaviorName CLOSE
   ;

